package com.drug.controller;

import com.drug.domain.DrugAtegory;
import com.drug.domain.DrugInformation;
import com.drug.domain.PurchaseOrder;
import com.drug.domain.Result;
import com.drug.service.PurchaseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.Map;

/**
 * 采购单控制层
 */
@Controller
public class PurchaseOrderController {

    @Autowired
    private PurchaseOrderService purchaseOrderService;

    /**
     * 查询全部分页
     */
    @ResponseBody
    @RequestMapping(value = "/PurchaseOrderController/findAll", produces = "application/json; charset=utf-8")
    private Result findConditional(@RequestParam Map<String,Object> map, @RequestParam(required=true,defaultValue="1")Integer pageNum) throws ParseException {
        return  purchaseOrderService.selectPurchaseOrder(map,pageNum);
    }


    /**
     * 修改(提交审核结果)
     * @param
     * @return
     */
    @RequestMapping(value="/DrugInformationController/updateSubmit", produces = "application/json; charset=utf-8")
    @ResponseBody
    public Result updateSubmit(@RequestParam String[] poAuditResult,@RequestParam Integer[] poId,@RequestParam String[]poAuditOpinion){
        Result result = new Result();
        PurchaseOrder purchaseOrder= new PurchaseOrder();
        for(int i = 0;i<poAuditResult.length;i++){
            Integer integer = poId[i];
            purchaseOrder.setPoId(integer);
            String str = poAuditResult[i];
            purchaseOrder.setPoAuditResult(str);
            String s = poAuditOpinion[i];
            purchaseOrder.setPoAuditOpinion(s);
            if ("0".equals(poAuditResult[i])){
                purchaseOrder.setPoState("1");
            }else if ("1".equals(poAuditResult[i])){
                purchaseOrder.setPoState("2");
            }//改变审核结果的时候同时改变采购单状态
            result = purchaseOrderService.updateSubmit(purchaseOrder);

        }
        return result;
    }
}
